import type { PageReq, PageRes } from '../common/commonApi'
import { useApi } from '@/composables/useApi'

export const NoticeStates = [
  { label: '未读', value: 'UNREAD', tagType: 'primary' },
  { label: '已读', value: 'READ', tagType: 'info' },
] as const
export type NoticeState = typeof NoticeStates[number]['value']

/**
 * 系统通知
 */
export interface Notice {
  /** 主键 */
  id?: number
  /** 标题 */
  title?: string
  /** 内容 */
  content?: string
  /** 链接 */
  link?: string
  /** 状态 */
  state: NoticeState
  /** 时间 */
  createTime?: string
}

/**
 * 系统通知查询参数
 */
export interface NoticeQuery extends PageReq {
  /** 主键 */
  id?: number
  /** 标题 */
  title?: string
  /** 状态 */
  state?: NoticeState
}

/**
 * 系统通知编辑状态参数
 */
export interface NoticeModifyStateCmd {
  /** 主键 */
  id: number
  /** 状态 */
  state: NoticeState
}

const basePath = '/system/notice'
export const noticeApi = {
  queryPage: useApi<NoticeQuery, PageRes<Notice>>(`${basePath}/page`).get,
  findDetail: async (id: number) => useApi<any, Notice>(`${basePath}/${id}`).get(),
  remove: async (id: number) => useApi<null, Notice>(`${basePath}/${id}`).remove(),
  modifyState: useApi<NoticeModifyStateCmd, any>(`${basePath}/page`).put,
}
